package com.zxy.h2demo;

import java.sql.*;

/**
 * App4.
 *
 * Created by zxybird on 17/1/13.
 */
public class App4 {

  private static String port = "8082";

  public static void main(String[] args) {
    try {
      Connection connection1 = null;
      Connection connection2 = null;

      connection1 = DriverManager.getConnection("jdbc:h2:mem:trump");
      connection2 = DriverManager.getConnection("jdbc:h2:mem:trump");

      Statement stmt1 = connection1.createStatement();
      Statement stmt2 = connection2.createStatement();

      stmt1.execute("CREATE SCHEMA IF NOT EXISTS TRUMP;");
      stmt1.execute("SET SCHEMA TRUMP;");
      stmt1.execute("CREATE TABLE `TRUMP`.`TEST_MEM` (ID INT PRIMARY KEY,NAME VARCHAR(255));");
      stmt1.execute("INSERT INTO `TRUMP`.`TEST_MEM` VALUES (1, 'Hello_Mem1');");
      stmt1.execute("INSERT INTO `TRUMP`.`TEST_MEM` VALUES (2, 'Hello_Mem2');");

//      ResultSet resultSet1 = stmt1.executeQuery("SELECT * FROM `TRUMP`.`TEST_MEM`");
//      while (resultSet1.next()) {
//        System.out.println(resultSet1.getInt(1));
//        System.out.println(resultSet1.getString(2));
//      }

      stmt2.execute("SET SCHEMA TRUMP;");
      stmt2.executeQuery("SELECT * FROM `TRUMP`.`TEST_MEM`");
      ResultSet resultSet2 = stmt2.executeQuery("SELECT * FROM `TRUMP`.`TEST_MEM`");
      while (resultSet2.next()) {
        System.out.println(resultSet2.getInt(1));
        System.out.println(resultSet2.getString(2));
      }

      System.out.println("链接创建成功！");

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
}
